<?php
 class Mddevice extends CI_Model
 {
    public function __construct()
    {
        parent::__construct();
        $this->load->database();   
        $this->load->library('table');
    }
    public function allDevice()
    {
        return $this->db->get("device")->result_array();
    }
    public function listDevice($limit, $start)
    {
        
        $this->db->limit($limit, $start);
        $this->db->select("device_id,d_name,d_imageDir");
        $query = $this->db->get("device");
        $data = $query->result_array();
        return $data;
        
    }
    
     public function listDeviceId($id_device)
    {
        $this->db->select();
        $this->db->where('device_id', $id_device);
        $query = $this->db->get("device");
        $data = $query->row_array();
        return $data;
    }
    
    public function addDevice($data)
    {
        $data = array(
                  'd_name'=>$data['d_name'],
                  'd_imageDir'=>$data['d_imageDir']
                );
        $this->db->insert('device',$data);
    }
     public function editDevice($id,$dataPost)
    {
        $data=array(
             "d_name" =>$dataPost['d_name'],
             "d_imageDir" => $dataPost['d_imageDir'], 
        );
        $this->db->where('device_id',$id);
        $this->db->update('device',$data);
    }
     public function delDevice($id=null)
    {
        $this->db->delete("device",array('device_id'=>$id));
    }
    
     public function record_count() {
        return $this->db->count_all("device");
    }
 
    
 }
?>